package com.sinosoft.dsp.platform.components.system;

import java.io.Serializable;

import org.primefaces.util.ArrayUtils;

import com.sinosoft.dsp.platform.components.AbstractViewBean;
import com.sinosoft.dsp.platform.utils.MessageBundles;
import com.sinosoft.dsp.platform.utils.SinoManagedBean;
import com.sinosoft.dsp.system.core.exception.SinoException;
import com.sinosoft.dsp.system.core.exception.SinoXMLException;
import com.sinosoft.dsp.system.utils.Const;

/**
 * 窗体模块视图
 * 
 * @since 1.0 2010-4-26
 * @author 潘巍（Peter Pan）
 * 
 */
public class WindowBean extends AbstractViewBean implements Serializable,
		IWindowBean {
	private static final long serialVersionUID = 3073564420566431104L;

	public static final String ATTRIBUTE_LABEL_IMAGE16 = "image16";
	public static final String ATTRIBUTE_LABEL_DISPLAY_NAME = "displayName";

	public static final String ATTRIBUTE_LABEL_WIDTH = "width";
	public static final String ATTRIBUTE_LABEL_HEIGHT = "height";
	public static final String ATTRIBUTE_LABEL_MIN_WIDTH = "minWidth";
	public static final String ATTRIBUTE_LABEL_MIN_HEIGHT = "minHeight";
	// 是否显示头部
	public static final String ATTRIBUTE_LABEL_SHOW_HEADER = "showHeader";
	// 是否可以最大化
	public static final String ATTRIBUTE_LABEL_MAXIMIZABLE = "maximizable";
	// 是否可以最小化
	public static final String ATTRIBUTE_LABEL_MINIMIZABLE = "minimizable";
	// 是否可以关闭
	public static final String ATTRIBUTE_LABEL_CLOSABLE = "closable";
	// 是否全屏
	public static final String ATTRIBUTE_LABEL_FULL_SCREEN = "fullScreen";
	// 是否可以调整大小
	public static final String ATTRIBUTE_LABEL_RESIZEABLE = "resizeable";
	// 是否固定位置
	public static final String ATTRIBUTE_LABEL_DRAGGABLE = "draggable";
	// 是否直接显示
	public static final String ATTRIBUTE_LABEL_VISIBLE = "visible";
	// 是否用蒙版遮蔽
	public static final String ATTRIBUTE_LABEL_MODAL = "modal";
	// 在显示时调用的JS
	public static final String ATTRIBUTE_LABEL_ON_SHOW = "onShow";
	// 在关闭时调用的JS
	public static final String ATTRIBUTE_LABEL_ON_HIDE = "onHide";

	public static final String[] ATTRIBUTE_STRING = new String[] {
			ATTRIBUTE_LABEL_IMAGE16, ATTRIBUTE_LABEL_DISPLAY_NAME,
			ATTRIBUTE_LABEL_ON_SHOW, ATTRIBUTE_LABEL_ON_HIDE };

	public static final String[] ATTRIBUTE_BOOLEAN = new String[] {
			ATTRIBUTE_LABEL_SHOW_HEADER, ATTRIBUTE_LABEL_MAXIMIZABLE,
			ATTRIBUTE_LABEL_MINIMIZABLE, ATTRIBUTE_LABEL_CLOSABLE,
			ATTRIBUTE_LABEL_FULL_SCREEN, ATTRIBUTE_LABEL_RESIZEABLE,
			ATTRIBUTE_LABEL_DRAGGABLE, ATTRIBUTE_LABEL_VISIBLE,
			ATTRIBUTE_LABEL_MODAL };

	public static final String[] ATTRIBUTE_INTEGER = new String[] {
			ATTRIBUTE_LABEL_WIDTH, ATTRIBUTE_LABEL_HEIGHT,
			ATTRIBUTE_LABEL_MIN_WIDTH, ATTRIBUTE_LABEL_MIN_HEIGHT };

	public static final String[] ATTRIBUTE = ArrayUtils.concat(
			ATTRIBUTE_STRING, ATTRIBUTE_BOOLEAN, ATTRIBUTE_INTEGER);

	@Override
	public void construct(String sceneId, String layout) throws SinoException {
		super.construct(sceneId, layout);
		reinit();
	}

	@Override
	public String getDisplayNameString() {
		MessageBundles mb = SinoManagedBean.findBean("messageBundles");
		return mb.getValue(getAttr(ATTRIBUTE_LABEL_DISPLAY_NAME),
				getAttr(ATTRIBUTE_LABEL_DISPLAY_NAME));
	}

	@Override
	public void reinit() throws SinoXMLException {
		MessageBundles mb = SinoManagedBean.findBean("messageBundles");
		if (Const.isEmpty(getAttr(ATTRIBUTE_LABEL_DISPLAY_NAME))) {
			putAttr(ATTRIBUTE_LABEL_DISPLAY_NAME, mb
					.getValue("portal.winSet.defaultWinHeader"));
		}
		putAttr(ATTRIBUTE_LABEL_IMAGE16, Const.DEFAULT_IMAGE16);

		putAttr(ATTRIBUTE_LABEL_MIN_WIDTH, "200");
		putAttr(ATTRIBUTE_LABEL_MIN_HEIGHT, "100");
		putAttr(ATTRIBUTE_LABEL_WIDTH, "");
		putAttr(ATTRIBUTE_LABEL_HEIGHT, "");
		
		putAttr(ATTRIBUTE_LABEL_SHOW_HEADER, Boolean.TRUE.toString());
		putAttr(ATTRIBUTE_LABEL_MAXIMIZABLE, Boolean.TRUE.toString());
		putAttr(ATTRIBUTE_LABEL_MINIMIZABLE, Boolean.TRUE.toString());
		putAttr(ATTRIBUTE_LABEL_CLOSABLE, Boolean.TRUE.toString());
		putAttr(ATTRIBUTE_LABEL_RESIZEABLE, Boolean.TRUE.toString());
		putAttr(ATTRIBUTE_LABEL_DRAGGABLE, Boolean.TRUE.toString());
		putAttr(ATTRIBUTE_LABEL_VISIBLE, Boolean.TRUE.toString());
		putAttr(ATTRIBUTE_LABEL_MODAL, Boolean.TRUE.toString());

	}

}
